package leetcode.Y2024M5D23;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class S228 {
    public List<String> summaryRanges(int[] nums) {
        int index = 0;
        List<String> res = new ArrayList<>();
        while (index < nums.length) {
            int start = nums[index];
            int end = start;
            while (index + 1 < nums.length && nums[index + 1] - 1 == nums[index]) {
                end = nums[++index];

            }
            String tmp;
            if (start == end) {
                tmp = start + "";

            } else {
                tmp = start + "->" + end;
            }
            index++;
            res.add(tmp);


        }
        return res;
    }

    @Test
    public void test() {
        int[] nums = {0, 1, 2, 4, 5, 7};
        System.out.println(summaryRanges(nums));
        int[] nums1={0,2,3,4,6,8,9};
        System.out.println(summaryRanges(nums1));

    }
}
